/**
 * Created by observer on 15/10/19.
 */
var leftBtn = $("#J-company-angle-left"),
    rightBtn = $("#J-company-angle-right"),
    wrap = $(".index-company-list"),
    list = $("#company-list"),
    item = list.find("li"),
    occupy = item.outerWidth(true), //每个元素的实际占位宽
    iLen = Math.ceil(item.length/2),
    listWidth =iLen *occupy,
    start = true,
    inAnimate = false;

list.css("width",listWidth);

leftBtn.on("click",{direction:"left"},function(){

    var position = list.position().left;

    if(position < 0 && !inAnimate){
        if(start){
            $(this).next().removeClass("control-ban");
            start = false;
        }
        if(position+occupy >= 0){
            $(this).addClass("control-ban");
            start = true;
        }
        inAnimate = true;
        list.animate({
            left: "+=" + occupy
        },500,"linear",function(){
            inAnimate = false;
        });
    }
});

rightBtn.on("click",function(){

    var position = list.position().left;

    if(position > -(iLen-6)*occupy && !inAnimate){
        if(start){
            $(this).prev().removeClass("control-ban");
            start = false;
        }
        if(position-occupy <= -(iLen-6)*occupy){
            $(this).addClass("control-ban");
            start = true;
        }
        inAnimate = true;
        console.log(inAnimate);
        list.animate({
            left: "-=" + occupy
        },500,"linear",function(){
            inAnimate = false;
        });

    }
});